package com.mzy.linear_struct.hot100.动态规划;

/**
 * @Author: mizy3
 * @Date: 2024/09/11/下午8:50
 * @Description:
 */
public class Pro64最小路径和 {
    public int minPathSum(int[][] grid) {
        // dp[i][j] 表示走到当前位置的最小路径
        for (int i = 1; i < grid.length; i++) {
            grid[i][0] += grid[i - 1][0];

        }

        for (int i = 1; i < grid[0].length; i++) {
            grid[0][i] += grid[0][i - 1];

        }
        // 1,2,3
        // 4,5,6

        // 1 3 6
        // 5 5 9
        for (int i = 1; i < grid.length; i++) {
            for (int j = 1; j < grid[i].length; j++) {
                grid[i][j] += Math.min(grid[i - 1][j], grid[i][j - 1]);
            }
        }

        return grid[grid.length - 1][grid[0].length - 1];
    }

    public static void main(String[] args) {
        // int[] score = new int[5];
        // int temp = score[0];
        // for (int index = 1; index < 5; index++) {
        //     if (score[index] < temp) {
        //         temp = score[index];
        //     }
        // }
        // new Pro64最小路径和().minPathSum(new int[][]{{1, 3, 1}, {1, 5, 1}, {4, 2, 1}});
    }
}



